package com.example.industry.service.impl;

import com.example.industry.dao.TaskDao;
import com.example.industry.entity.Task;
import com.example.industry.enums.TaskStatus;
import com.example.industry.service.TaskService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskServiceImpl implements TaskService
{
    @Resource
    private TaskDao taskDao;

    @Override
    public boolean createTask(Integer projectId, String introduction)
    {
        Task task = new Task();
        task.setIntroduction(introduction);
        task.setStatus(TaskStatus.RUNNING);
        return taskDao.addTask(task);
    }

    @Override
    public boolean updateTask(Integer taskId, String introduction, TaskStatus status)
    {
        Task task = taskDao.findById(taskId);
        if (task != null)
        {
            task.setIntroduction(introduction);
            task.setStatus(status);
            return taskDao.update(task);
        }
        return false;
    }

    @Override
    public boolean deleteTask(Integer taskId)
    {
        return taskDao.deleteById(taskId);
    }

    @Override
    public boolean assignTask(Integer projectId, String introduction, Integer assignerId, List<Integer> users)
    {
        Task task = new Task();
        task.setProjectId(projectId);
        task.setIntroduction(introduction);
        task.setStatus(TaskStatus.RUNNING);
        task.setAssignerID(assignerId);
        task.setAccepterId(users);
        return taskDao.addTask(task);
    }
}
